<!DOCTYPE html>
<html lang="en">
    <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
          http://www.apache.org/licenses/LICENSE-2.0
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    <head>
        <meta charset="utf-8" />
        <title>ConvertAvroSchema</title>

        <link rel="stylesheet" href="../../../../../css/component-usage.css" type="text/css" />
    </head>

    <body>
        <!-- Processor Documentation ================================================== -->
        <h2>Description:</h2>
        <p>This processor is used to convert data between two Avro formats, such as those coming from the <code>ConvertCSVToAvro</code> or
            <code>ConvertJSONToAvro</code> processors. The input and output content of the flow files should be Avro data files. The processor
            includes support for the following basic type conversions:
            <ul>
              <li>Anything to String, using the data's default String representation</li>
              <li>String types to numeric types int, long, double, and float</li>
              <li>Conversion to and from optional Avro types</li>
            </ul>
            In addition, fields can be renamed or unpacked from a record type by using the dynamic properties.
         </p>
         <h2>Mapping Example:</h2>
         <p>
             Throughout this example, we will refer to input data with the following schema:
             <pre>
{
    "type": "record",
    "name": "CustomerInput",
    "namespace": "org.apache.example",
    "fields": [
        {
            "name": "id",
            "type": "string"
        },
        {
            "name": "companyName",
            "type": ["null", "string"],
            "default": null
        },
        {
            "name": "revenue",
            "type": ["null", "string"],
            "default": null
        },
        {
            "name" : "parent",
            "type" : [ "null", {
              "type" : "record",
              "name" : "parent",
              "fields" : [ {
                "name" : "name",
                "type" : ["null", "string"],
                "default" : null
              }, {
                "name" : "id",
                "type" : "string"
              } ]
            } ],
            "default" : null
        }
    ]
}
             </pre>
             Where even though the revenue and id fields are mapped as string, they are logically long and double respectively.
             By default, fields with matching names will be mapped automatically, so the following output schema could be converted
             without using dynamic properties:
             <pre>
{
    "type": "record",
    "name": "SimpleCustomerOutput",
    "namespace": "org.apache.example",
    "fields": [
        {
            "name": "id",
            "type": "long"
        },
        {
            "name": "companyName",
            "type": ["null", "string"],
            "default": null
        },
        {
            "name": "revenue",
            "type": ["null", "double"],
            "default": null
        }
    ]
}
             </pre>
             To rename companyName to name and to extract the parent's id field, both a schema and a dynamic properties must be provided.
             For example, to convert to the following schema:
             <pre>
{
    "type": "record",
    "name": "SimpleCustomerOutput",
    "namespace": "org.apache.example",
    "fields": [
        {
            "name": "id",
            "type": "long"
        },
        {
            "name": "name",
            "type": ["null", "string"],
            "default": null
        },
        {
            "name": "revenue",
            "type": ["null", "double"],
            "default": null
        },
        {
            "name": "parentId",
            "type": ["null", "long"],
            "default": null
        }
    ]
}
             </pre>
             The following dynamic properties would be used:
             <pre>
"companyName" -> "name"
"parent.id" -> "parentId"
             </pre>
        </p>
</body>
</html>
